function Get-TFSPath {
    $versions=(get-ChildItem HKLM:SOFTWARE\Wow6432Node\Microsoft\VisualStudio -ErrorAction SilentlyContinue | ? { 
        ($_.Name -match ".*\\[0-9\.]+$") 
    } | ? {
        $_.property -contains "InstallDir"
    } | sort-object -property @{Expression={[int]$_.PSChildName};descending=$true})

    if($versions -and $versions.Length){
        $version = $versions[0]
    }elseif($versions){
        $version = $versions
    }

    if(!$version){
        throw "The TFS Version Control Client could not be found."
    }

    $vnum=$version.PSPath.Substring($version.PSPath.LastIndexOf('\')+1)
    $dir=(get-itemProperty $version.PSPath "InstallDir").InstallDir 
    return Join-Path $dir "tf.exe"
}
